package main.java.day08;

import java.io.*;

/**
 * 对myfile.txt文件进行复制操作，要求使用异常捕获
 * 机制对流的异常进行捕获和处理，finally中
 * 要将流关闭
 *
 * @author Xiloer
 */
public class Test01 {
    public static void main(String[] args) {
        FileInputStream in = null;
        FileOutputStream out = null;
        try {
            in = new FileInputStream("myfile.txt");
            out = new FileOutputStream("myfile.txt");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        int a = 0;
        byte[] buff = new byte[1024];
        while (true) {
            try {
                if (!((a = in.read(buff)) != -1)) break;
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                out.write(buff);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        try {
            in.close();
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}